<?php
    class ARingCategory extends CActiveRecord
    {
        public static function model($className = __CLASS__)
        {
            return parent::model ( $className );
        }
        // goi den bang can ket noi   
        public function tableName() 
        {                  
            return 'c_ring_category';
        }  

        public function getDataById($id){ 
            $sql = "SELECT * FROM c_ring_category WHERE id = ".$id;  
            $connect = Yii::app()->db;
            $command = $connect->createCommand($sql);
            $data = $command->queryAll();
            return $data ;
        }      

        public function getAllData(){
            $str_sql = "";
            $sql = "SELECT id,title FROM c_ring_category WHERE 1 ".$str_sql."";
            $connect = Yii::app()->db;
            $command = $connect->createCommand($sql);
            $rows = $command->queryAll();
            for($i=0;$i<count($rows);$i++){
                $data[$rows[$i]["id"]] = $rows[$i]["title"]; 
            }
            return isset($data) ? $data : array();
        }
        
        public function getAllCategory()
        {
            $sql = "SELECT * FROM c_ring_category ORDER BY id DESC";
            $connect = Yii::app()->db;
            $command = $connect->createCommand($sql);
            $data = $command->queryAll();
            return $data;
        } 
        
        public function getDataByCategory($id){ 
            $sql = "SELECT * FROM c_ring_category WHERE id = ".$id;  
            $connect = Yii::app()->db;
            $command = $connect->createCommand($sql);
            $data = $command->queryRow();
            return $data;
        }  
    }
?>
